<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="http://richfaces.org/a4j" xmlns:p="http://primefaces.org/ui"
	xmlns:t="http://myfaces.apache.org/tomahawk" template="/pages/template/main-layout-oa.xhtml">
	<ui:define name="head">
		<script type="text/javascript">  
		function handleSubmitEvent(xhr, status, args) {  
			if(args.validationFailed) {  
				//jQuery('#docScheduleDialog').effect("shake", { times:3 }, 100);  
			} else {  
				docScheduleDlg.hide();
			 }  
		}
		</script>
	</ui:define>
	<ui:define name="content">
		<h:panelGrid columns="2" width="100%" columnClasses="width80,width20" cellpadding="5">
			<p:schedule id="patientSchedule" value="#{patientScheduleBean.lazyEventModel}" locale="hr"
				widgetVar="myschedule" resizable="false" draggable="false">
				<p:ajax event="dateSelect" listener="#{patientScheduleBean.onDateSelect}"
					update=":dialogform:userEventDetails,:dialogform:docScheduleDialog" oncomplete="docScheduleDlg.show()" />

				<p:ajax event="eventSelect" listener="#{patientScheduleBean.onEventSelect}"
					update=":dialogform:userEventDetails,:dialogform:docScheduleDialog" oncomplete="docScheduleDlg.show()" />
			</p:schedule>

			<p:dataTable value="#{patientScheduleBean.todoList}" var="cm" id="todaylist">
				<p:column styleClass="tableNoBorder" headerText="#{msgs.patient_reservations}">
					<h:outputText style="font-weight: bold;" value="#{cm[0]}" escape="false"/>
					<br />
					<h:outputText value="#{msgs.default_query_datefrom} " />
					<h:outputText value="#{cm[1]}" converter="dateTimeConverter" />
					<br />
					<h:outputText value="#{msgs.default_query_dateto} " />
					<h:outputText value="#{cm[2]}" converter="dateTimeConverter" />
				</p:column>
			</p:dataTable>
		</h:panelGrid>
	</ui:define>
	<ui:define name="dialog">
		<p:dialog widgetVar="docScheduleDlg" header="#{patientScheduleBean.header}" showEffect="clip"
			hideEffect="clip" closable="true" modal="true" width="800" height="550" id="docScheduleDialog">
			<h:panelGrid id="userEventDetails" width="100%">
				<h:panelGrid columns="2" width="100%" cellpadding="5" columnClasses="width30,width70">
					<h:outputLabel value="#{msgs.patient_therapy_type}" />
					<h:outputText value="#{patientScheduleBean.calendarType}" converter="enumConverter" enumName="CalendarType"/>
				</h:panelGrid>

				<p:panel visible="#{patientScheduleBean.calendarType == 1}" id="pnlPatient">
					<h:panelGrid columns="2" width="100%" cellpadding="5" columnClasses="width30,width70">
						<h:outputLabel value="#{msgs.default_priority}" />
						<p:selectBooleanCheckbox value="#{patientScheduleBean.doctorSchedule.priority}" disabled="true"/>

						<h:outputLabel value="#{msgs.default_status}" />
						<h:outputText value="#{patientScheduleBean.doctorSchedule.status}" converter="enumConverter" enumName="ReservationStatus"/>
					</h:panelGrid>
					<p:panel visible="#{patientScheduleBean.therapyObj != null}"
						header="#{msgs.patient_therapy_title}" id="pnlTherapy">
						<p:panelGrid columns="2" width="100%" cellpadding="5" columnClasses="width30,width70">
							<h:outputLabel value="#{msgs.patient_therapy_startDate}" />
							<h:outputText value="#{patientScheduleBean.therapyObj[0]}" converter="dateConverter" />

							<h:outputLabel value="#{msgs.therapy_category}" />
							<h:outputText value="#{patientScheduleBean.therapyObj[1]}" />

							<h:outputLabel value="#{msgs.default_status}" />
							<h:outputText value="#{patientScheduleBean.therapyObj[2]}" converter="enumConverter"
								enumName="TherapyStatus" />
						</p:panelGrid>
					</p:panel>
				</p:panel>

				<h:panelGrid columns="2" width="100%" cellpadding="5" columnClasses="width30,width70">
					<h:outputLabel for="title" value="#{msgs.default_remark}" />
					<p:inputTextarea id="title" value="#{patientScheduleBean.sEvent.title}" required="true"
						label="#{msgs.default_remark}"
						style="validator:checkNotNull(#{msgs.default_remark});width:100%" rows="5" autoResize="false" />

					<h:outputLabel value="#{msgs.default_from}" />
					<p:calendar value="#{patientScheduleBean.sEvent.startDate}" timeZone="Europe/Zagreb"
						required="true" label="#{msgs.default_from}"
						style="validator:checkNotNull(#{msgs.default_from})" pattern="dd/MM/yyyy HH:mm"
						showOn="button" />

					<h:outputLabel value="#{msgs.default_to}" />
					<p:calendar value="#{patientScheduleBean.sEvent.endDate}" timeZone="Europe/Zagreb"
						required="true" label="#{msgs.default_to}" 
						style="validator:checkNotNull(#{msgs.default_to})" showOn="button"
						pattern="dd/MM/yyyy HH:mm" />

					<f:facet name="footer">
						<h:panelGrid columns="2" width="100%" columnClasses="left,right">
							<p:commandButton value="#{msgs.button_delete}" rendered="#{patientScheduleBean.calendarType == 2}"
								immediate="true"
								actionListener="#{patientScheduleBean.deleteEvent}" icon="ui-icon-trash"
								oncomplete="myschedule.update();docScheduleDlg.hide();"
								update=":messages,:mainform:todaylist" style="float:left" />

							<h:panelGroup style="float:right">
								<p:commandButton value="#{msgs.button_submit}"
									rendered="#{patientScheduleBean.calendarType == 2}"
									actionListener="#{patientScheduleBean.submitEventAction}" icon="ui-icon-disk"
									oncomplete="handleSubmitEvent(xhr, status, args);myschedule.update();"
									update=":messages,:mainform:todaylist" />
								<h:outputText value="&#160;&#160;" escape="false" />
								<p:commandButton value="#{msgs.patient_therapy_go}"
									rendered="#{patientScheduleBean.therapyObj != null}"
									action="#{patientScheduleBean.goTherapyAction}" ajax="false"
									icon="ui-icon-arrowreturnthick-1-e" />
							</h:panelGroup>
						</h:panelGrid>
					</f:facet>
				</h:panelGrid>
			</h:panelGrid>
		</p:dialog>
	</ui:define>
</ui:composition>
